﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Management_MedicalDirector_RoomManagement : System.Web.UI.Page
{
    static int currentWard;
    static string currentWardLocation;
    static int currentRoom;
    static string currentRoomName;

    protected override void OnLoad(EventArgs e)
    {
        if (!IsPostBack)
        {
            khoaDS.DataBind();
        }
    }

    protected void ward_onclick(object sender, EventArgs e)
    {
        LinkButton lb = (sender as LinkButton);
        string[] args = lb.CommandArgument.Split(',');
        currentWard = Int32.Parse(args[0]);
        currentWardLocation = args[1];
        phongDS.SelectParameters["IDWard"].DefaultValue = currentWard.ToString();
        phongDS.DataBind();
        Panel2.Visible = true;
    }
    protected void btThem_Click(object sender, EventArgs e)
    {
        if (tbTenkhoa.Text.Equals(""))
        {
            lbValiName.Text = "Không được để trống";
            lbValiTel.Text = "";
            lbValiLocation.Text = "";
            tbTenkhoa.Focus();
        }
        else
        {
            if (tbLocation.Text.Equals(""))
            {
                lbValiLocation.Text = "Không được để trống";
                lbValiTel.Text = "";
                lbValiName.Text = "";
                tbLocation.Focus();
            }
            else
            {
                if (tbMayle.Text.Equals(""))
                {
                    lbValiTel.Text = "Không được để trống";
                    lbValiName.Text = "";
                    lbValiLocation.Text = "";
                    tbMayle.Focus();
                }
                else 
                {
                    khoaDS.InsertParameters["Name"].DefaultValue = tbTenkhoa.Text;
                    khoaDS.InsertParameters["Location"].DefaultValue = tbLocation.Text;
                    khoaDS.InsertParameters["TelExt"].DefaultValue = tbMayle.Text;
                    tbTenkhoa.Text = "";
                    tbLocation.Text = "";
                    tbMayle.Text = "";
                    lbValiTel.Text = "";
                    lbValiName.Text = "";
                    lbValiLocation.Text = "";
                    khoaDS.Insert();
                    khoaDS.DataBind();
                }
            }
        }

        
    }

    protected void btAddRoom_Click(object sender, EventArgs e)
    {
        if (tbRoomName.Text.Equals(""))
        {
            tbRoomName.Focus();
            lbValiRoom.Text = "trống";
        }
        else 
        {
            lbValiRoom.Text = "";
            phongDS.InsertParameters["IDWard"].DefaultValue = currentWard.ToString();
            phongDS.InsertParameters["RoomName"].DefaultValue = currentWardLocation + tbRoomName.Text;
            phongDS.Insert();
            tbRoomName.Text = "";
            phongDS.DataBind();
        }
        
    }

    protected void btRoom_Click(object sender, EventArgs e)
    {
        LinkButton lb = (sender as LinkButton);
        string[] args = lb.CommandArgument.Split(',');
        currentRoom = Int32.Parse(args[0]);
        currentRoomName = args[1];
        giuongDS.SelectParameters["IDRoom"].DefaultValue = currentRoom.ToString();
        giuongDS.DataBind();
        Panel3.Visible = true;
    }
    protected void btAddBed_Click(object sender, EventArgs e)
    {
        if (tbBedName.Text.Equals(""))
        {
            tbBedName.Focus();
            lbValiBed.Text = "trống";
        }
        else
        {
            lbValiBed.Text = "";
            giuongDS.InsertParameters["IDRoom"].DefaultValue = currentRoom.ToString();
            giuongDS.InsertParameters["BedName"].DefaultValue = currentRoomName + "." + tbBedName.Text;
            giuongDS.Insert();
            giuongDS.DataBind();
            tbBedName.Text = "";
        }
        
    }
}